/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Teste.java
 *
 * Created on 28/06/2011, 16:06:30
 */

package Testes;

import java.util.Locale;
import java.util.ResourceBundle;
import java.util.logging.Logger;
import javax.security.auth.Refreshable;

/**
 *
 * @author pc
 */
public class Teste extends javax.swing.JFrame {

    private static Logger log = Logger.getLogger(Teste.class.getName());
    private static ResourceBundle myResources =
        ResourceBundle.getBundle("Testes/messages", Locale.getDefault());

    public static final Locale localUS = new Locale("en_US");
    public static final Locale localBR = new Locale("pt_BR");

    /** Creates new form Teste */
    public Teste() {

        initComponents();

        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("Testes/messages"); // NOI18N
        jLabel1.setText(bundle.getString("label.rotulo")); // NOI18N

        jButton1.setText("pt_BR");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("en_US");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("jButton3");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jMenu1.setText(bundle.getString("menu.arquivo")); // NOI18N

        jMenuItem1.setText(bundle.getString("menuitem.salvar")); // NOI18N
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        jMenu2.setText(bundle.getString("menu.editar")); // NOI18N
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(67, 67, 67)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 125, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addGap(131, 131, 131))
            .addGroup(layout.createSequentialGroup()
                .addGap(160, 160, 160)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton3)
                    .addComponent(jLabel1))
                .addContainerGap(193, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(66, 66, 66)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton1))
                .addGap(75, 75, 75)
                .addComponent(jButton3)
                .addContainerGap(53, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        Locale.setDefault(localBR);

        Locale locale = Locale.getDefault();
        ResourceBundle rb = ResourceBundle.getBundle("Testes.messages", locale);

        jMenu1.setText(rb.getString("menu.arquivo"));
        jMenuItem1.setText(rb.getString("menuitem.salvar"));
        jMenu2.setText(rb.getString("menu.editar"));
        jLabel1.setText(rb.getString("label.rotulo"));

        System.out.println(Locale.getDefault());
        log.info(myResources.getString("log.idioma.trocado.br"));
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        Locale.setDefault(localUS);
    
        Locale locale = Locale.getDefault();
        ResourceBundle rb = ResourceBundle.getBundle("Testes.messages_en_US", locale);

        jMenu1.setText(rb.getString("menu.arquivo"));
        jMenuItem1.setText(rb.getString("menuitem.salvar"));
        jMenu2.setText(rb.getString("menu.editar"));
        jLabel1.setText(rb.getString("label.rotulo"));

        System.out.println(Locale.getDefault());
        log.info(myResources.getString("log.idioma.trocado.us"));
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        Teste_2 t2 = new Teste_2();
        t2.setVisible(true);

    }//GEN-LAST:event_jButton3ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Teste().setVisible(true);
                log.severe(myResources.getString("log.test"));
                log.info(myResources.getString("log.test.info"));
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    // End of variables declaration//GEN-END:variables

}
